<template>
  <div>
    添加学生
    <input type="text" v-model='form.name'>
    <input type="text" v-model='form.age'>
    <button @click='add'>添加</button>

    <br>
    展示此老师下的所有学生
    <ul>
      <li v-for='i in stulist'>{{i.name}}</li>
    </ul>
  </div>
</template>
<script>
export default {
  name:'student',
  data(){
    return{
      form:{'teacher':localStorage.getItem('tuserid')},
      stulist:[],
      tid:localStorage.getItem('tuserid')
    }
  },
  methods: {
    add(){
      this.axios.post('goods/stuM/',this.form).then(res=>{
        this.getStulist()
      })
    },
    getStulist(){
      this.axios.get('goods/stuM/?tid='+this.tid).then(res=>{
        if(res.data.code == 200){
          this.stulist=res.data.list
        }
      })
    }
  },
  mounted() {

    if(!this.tid){
      alert('请登录后操作')
      this.$router.push({"path":'/tlogin'})
    }

    this.getStulist()
  },
}
</script>

<style scoped>

</style>
